﻿window.InboxEngineJob = {};
InboxEngineJob.Url = ""; //全局变量用于切换跳转
InboxEngineJob.JobID; //当前职位id
InboxEngineJob.AttentionFlag; //是否关注职位
//初始化txt事件
$("[id^='txt_']").click(function () {
    //只读--下拉框
    if ($(this).attr("readonly")) {
        $(this).blur();
        $(this).siblings("a").click();
    }
    else {
        //文本框
        $(this).blur(function () {
            $(this).css('border-color', '#bfbfbf');
        }).focus(function () {
            $(this).css('border-color', '#5191ce');
        });
    }
});
//绑定搜索按钮
$('.btn-search').bind("click", function () {
        $('#btnSelect')[0].click();
});
//初始化排序事件
$(".list-table thead .blue_link").click(function () {
    $("#hidSort").val($(this).attr("value"));
    $("#btnSort")[0].click();
});
//初始化取消关注事件
$("#job-list-table").find(".icon-star").live("click", function () {
    InboxEngineJob.InitClick(this, 0);
});
//初始化关注职位事件
$("#job-list-table").find(".icon-star-empty").live("click", function () {
    InboxEngineJob.InitClick(this, 1);
});
//初始化placehold
EHRCommonSearch.CreatePlaceholder();
/**************************************************公司、部门、职位状态、职位类型*****************************************/
//<%---------------------------------------进度框浮层AjaxLoading----------------------------------------%>
InboxEngineJob.divAjaxLoading01 = "<table style='width: 165px; height: 28px; line-height: 26px; margin: 0px; margin-top: 1px;margin-bottom: 1px;'>"
            + "<tr>"
                + "<td style='width: 100%; color: #666666;' align='center'>"
                    + "<img src='" + ImagePath + "common/loading2.gif' style='padding-right: 10px; height: 20px;width: 20px; vertical-align: middle;' alt='' />" + loading
                + "</td>"
            + "</tr>"
        + "</table>";

//公司部门下拉框
InboxEngineJob.InitComDiv = function (initID) {
    $(initID).click(function (e) {
        //$("#div_searchlist .inptext_fl").children("input").css("border-color", "#c4c4c4");
        var controlID = $(this).attr('id').replace('drop_', '');
        var obj = $(this).children("div.downList"); //页面上公司部门
        var thisID = $(this).attr('id');
        if (thisID.indexOf('_box') > 0) {
            //弹层公司部门
            obj = $(this).children("div.gdownList");
        }
        if (obj.is(":hidden")) {
            $("[id^='divdrop_']").hide();
            if ($.trim($("#divdrop_" + controlID).html()) == "") {
                companyObj = obj;
                var postData = [];
                if (controlID.indexOf('company') >= 0) {
                    postData = { "doType": "GetInboxJobCompany" };
                    InboxEngineJob.GetCompanyList(controlID, postData);
                }
                else if (controlID.indexOf('division') >= 0) {
                    postData = { "doType": "GetInboxJobDivision", "c": $("#hid_" + controlID.replace('division', 'company')).val() };
                    InboxEngineJob.GetCompanyList(controlID, postData);
                }
            }
            $('#txt_' + controlID).css('border-color', '#5191ce');
            $("#divdrop_" + controlID).css('width', parseInt($('#drop_' + controlID).css('width')) - 2 + 'px');
            obj.show();
        }
        else {
            //var target = getEvent().target || getEvent().srcElement;
            e = e || window.event;
            target = e.target || e.srcElement;
            var targetId = target.id || '';
            var targetHtml = target.innerText || nolimited;
            var hidval = $('#hid_' + controlID).val();
            if (targetId.indexOf('dic_') >= 0) {
                $('#txt_' + controlID).val(targetHtml);
                var selectID = targetId != '' ? targetId.split('_')[2] : '';
                $('#hid_' + controlID).val(selectID);
                $("#divdrop_" + controlID).css('height', '');
                if (selectID == '')
                    $('#txt_' + controlID).css("color", "#bfbfbf");
                else
                    $('#txt_' + controlID).css("color", "#4c4c4c")
                if (controlID.indexOf('company') >= 0) {
                    if (hidval != selectID) {
                        $("#divdrop_" + controlID.replace('company', 'division')).html("");
                        $("#txt_" + controlID.replace('company', 'division')).val(nolimited);
                        $("#txt_" + controlID.replace('company', 'division')).css("color", "#bfbfbf")
                        $("#hid_" + controlID.replace('company', 'division')).val("");
                        
                    }
                }
                $("[id^='divdrop_']").hide();
                $('#txt_' + controlID).css('border-color', '#c4c4c4');
            }
        }
    });
    $(initID).each(function () {
        $(this).mouseleave(function () {
            if ($(this).children("input[type='text']").attr("readonly")) {
                $(this).children(".downList,.gdownList").hide();
                $(this).children("input[type='text']").css("border-color", "#c4c4c4");
            }
        });
    });
}


//获取公司/部门列表
InboxEngineJob.GetCompanyList = function (controlID, postData) {

    if ($("#divdrop_" + controlID).html().toString().trim() == "") {

        $.ajax(
          {
              type: "post",
              async: true,
              dataType: 'xml',
              url: "../Ajax/InboxResume/GlobalInboxCommonAjax.ashx",
              data: postData,
              beforeSend: function (XMLHttpRequest) {
                  $("#divdrop_" + controlID).show();
                  $("#divdrop_" + controlID).html(InboxEngineJob.divAjaxLoading01);
              },
              success: function (result) {

                  $("#divdrop_" + controlID).html($(result).find("returninfo").eq(0).text());
                  var coidLength = $("#divdrop_" + controlID + " a").length;
                  if (coidLength <= 10) {
                      $("#divdrop_" + controlID).css("height", coidLength * 28);
                  }
                  else {
                      $("#divdrop_" + controlID).css("height", 280);
                      if (controlID.indexOf('_box') < 0) {
                          $("#divdrop_" + controlID + " a").each(function () {
                              $(this).css("width", 136);
                          });
                      }
                  }

              },
              error: function (XMLHttpRequest, textStatus, errorThrown) {

              }
          });
    }

}
/**************************************************公司、部门End*****************************************/

/*查看公司*/
InboxEngineJob.GetJobViewHtml = function (obj, jobid, e) {
    var postData = {
        "doType": "GetJobViewHtml",
        "JobID": jobid
    };
    $.ajax({
        async: false,
        url: '../Ajax/InboxResume/GlobalInboxCommonAjax.ashx',
        data: postData,
        type: 'POST',
        dataType: 'xml',
        success: function (result) {
            var msgtype = $(result).find("msgtype").eq(0).text();
            var returninfo = $(result).find("returninfo").eq(0).text();
            if (msgtype == "0") {
                EHR.ShowBox(returninfo, 300);
                return;
            }
            if ($("#div_jobview").length > 0) {
                $("#div_jobview").remove();
            }
            $("body").append("<div class='panel_lnp' id='div_jobview' style='width:434px;'></div>");
            $("#div_jobview").html(returninfo);
            //            e = e||window.event;
            //            var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
            //            var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
            //            var x = e.pageX || e.clientX + scrollX;
            //            var y = e.pageY || e.clientY + scrollY;

            //var obj= $("#a_jobview");
            //$("#divdrop_process").css({ "top": obj.offset().top + 15, "left": obj.offset().left });
            $("#div_jobview").css({
                //                "top": $(obj).offset().top + $(obj).height() / 2,
                //                "left": $(obj).offset().left + $(obj).width(),
                "z-index": 200,
                position: "absolute"
            });
            $("#div_jobview").mouseout(function () {
                InboxEngineJob.LosetJobViewPosition();
            }).mouseover(function () {
                InboxEngineJob.SetJobViewPosition();
            }).show();
            $(obj).parent('td').mouseout(function () {
                InboxEngineJob.LosetJobViewPosition();
            });
            InboxEngineJob.fallowMouse(e, $("#div_jobview"), '', obj);
        }
    });
}
//鼠标定位,left固定，top变化
InboxEngineJob.fallowMouse = function (e, obj, dir, aObj) {
    //     e = e || window.event;
//    dir = dir || { left: false, top: false };
//    var ex = e.clientX;
//    var ey = e.clientY;
//    var bl = document.body.scrollLeft || document.documentElement.scrollLeft;
//    var bt = document.body.scrollTop || document.documentElement.scrollTop;
//    var bw = document.body.offsetWidth || document.documentElement.offsetWidth;
//    var bh = document.documentElement.clientHeight;
//    var bh = this.getPageWHT.height();
//    var ow = obj[0].offsetWidth;
//    var oh = obj[0].offsetHeight;
//    var ol = dir.left ? (ex - ow < bl ? ex + bl : ex + bl - ow) : (ex + ow > bw ? ex + bl - ow : ex + bl);
//    ol = Math.max(0, bl, ol);
//    var ot = dir.top ? (ey - oh < bt ? ey + bt : ey + bt - oh) : (ey + oh > bh ? ey + bt - oh : ey + bt);
//    ot = Math.max(0, bt, ot);
    //obj.css('left', ol + 'px'); //offset().left + $(obj).width()

    var bt = document.body.scrollTop || document.documentElement.scrollTop;
    //页面可视区域
    var bh = document.documentElement.clientHeight;
    //元素相对位置
    var at = $(aObj).offset().top;
    //元素高度
    var ah = $(aObj).height();
    //弹框高度
    var oh = obj[0].offsetHeight;
    var ot = '';
    //底部预留10px
    if (at + oh+10-bt > bh)
        ot = at - oh + ah / 2;
    else
        ot = at + ah / 2;
    obj.css('left', ($(aObj).offset().left + $(aObj).width()) + 'px');
    obj.css('top', ot + 'px');
}
/*设置、取消关注*/
InboxEngineJob.IsJobAttention = 0; //是否已发送请求
InboxEngineJob.InitClick = function (obj,type) {
    InboxEngineJob.JobID = $(obj).attr("value");
    InboxEngineJob.AttentionFlag = type;
    InboxEngineJob.SetJobAttention();
}
InboxEngineJob.SetJobAttention = function () {
    if (InboxEngineJob.IsJobAttention)
        return;
    InboxEngineJob.IsJobAttention = 1;
    var postData = {
        "doType": "SetJobAttention",
        "jobid": InboxEngineJob.JobID,
        "isattention": InboxEngineJob.AttentionFlag,
        'ishis':$('#isHis').val()
    };
    EHR.Common_AsyncHandle("POST", "xml", "../Ajax/InboxResume/GlobalInboxCommonAjax.ashx", postData, InboxEngineJob.SetJobAttentionResult, 0);
}
//设置取消关注结果
InboxEngineJob.SetJobAttentionResult = function (result) {
    var msgtype = $(result).find("msgtype").eq(0).text();
    if (msgtype == "1") {
        if ($('#isHis').val() == "1")
            $('#btnRefreshPage')[0].click();
        else {
            InboxEngineJob.IsJobAttention = 0;
            var obj = $('a[value="' + InboxEngineJob.JobID + '"]');
            obj.die('click');
            if (obj.hasClass("icon-star")) {
                obj.attr('class', 'icon icon-star-empty');
                obj.attr('title', inboxNew_Follow);
                obj.live('click', function () {
                    InboxEngineJob.InitClick(this, 1);
                })

            } else {
                obj.attr('class', 'icon icon-star');
                obj.attr('title', inboxNew_UnFollow);
                obj.live('click', function () {
                    InboxEngineJob.InitClick(this, 0);
                });

            }
            //icon 
        }
    }
    else {
        EHR.ShowBox($(result).find("returninfo").eq(0).text(), 300);
        InboxEngineJob.IsJobAttention = 0;
    }
}
InboxEngineJob.SetJobViewPosition = function () {
    $('#div_jobview').css('display', 'block');
    return false;   
}
InboxEngineJob.LosetJobViewPosition = function () {
    $('#div_jobview').css('display', 'none');
    return false;
}
/*应聘管理新版建议反馈*/
InboxEngineJob.FeedBack = function (type) {
    var evaluate = $("#FeedBack_Evaluate").attr("sid");
    if (isNaN(evaluate)) { evaluate = ""; }
    if (evaluate == "") {
        InboxEngineJob.showErrorTemp("Evaluate", inboxNew_FeedBackErr);
        return;
    }
    //建议内容只能为纯文本内容
    if (HasHtmlTag($("#FeedBack_Content").val())) {      //信件内容不能含有html标签
        InboxEngineJob.showErrorTemp("Content", inboxNew_FeedBackLimitHtml);
        return;
    }

    var strmsg = $("#FeedBack_Content").val() + "(" + evaluate + ")";
    var postData = { doType: 'FeedBack', feed: strmsg };
    EHR.Common_AsyncHandle("POST", "xml", "../Ajax/InboxResume/GlobalInboxCommonAjax.ashx", postData, InboxEngineJob.SetFeedBackResult);
}
/*应聘管理新版建议反馈结果处理*/
InboxEngineJob.SetFeedBackResult = function (result) {
    var content = $(result).find('returninfo').eq(0).text();
    EHR.CloseDivBox("#divCtlFeedBack");
    EHR.ShowBox(content, 350);
}
/* 建议反馈错误提示 */
InboxEngineJob.showErrorTemp = function (type, content) {
    $("#err_" + type).html(content);
    $("#err_" + type).show();
}
/*返回旧版*/
InboxEngineJob.GoToOldPage = function (url) {
    InboxEngineJob.Url = url;
    var postData = { doType: 'GoToPage',pagecode: "3" };
    EHR.Common_AsyncHandle("POST", "xml", "../Ajax/InboxResume/GlobalInboxCommonAjax.ashx", postData, InboxEngineJob.SetToOldPageResult,0);
}
/*返回旧版结果处理*/
InboxEngineJob.SetToOldPageResult = function (result) {
    var msgType = $(result).find('msgtype').eq(0).text();
    var content = $(result).find('returninfo').eq(0).text();
    if (msgType == "1") {
        window.location.href = InboxEngineJob.Url;
    }
    else {
        EHR.ShowBox(content, 350);
    }
}
/*应聘管理建议反馈操作小星星*/
InboxEngineJob.setStarFun = function (arrLi) {
    for (var i = 0; i < arrLi.length; i++) {
        arrLi[i].index = i + 1;
        arrLi[i].onmouseover = function () {
            //显现值几个星星
            InboxEngineJob.ShowTars(this.index, arrLi);
        };

        //鼠标离开后恢复到上次显现的几个星星
        arrLi[i].onmouseout = function () {
            var sidNum = $(this).parent().attr('sid');
            InboxEngineJob.ShowTars(sidNum, arrLi); // 显现值几个星星
        };

        //点击后进行评分处理
        arrLi[i].onclick = function () {
            $(this).parent().attr('sid', this.index);
            $("#err_Evaluate").hide();
        };
    }
};
// 显现值几个星星
InboxEngineJob.ShowTars = function (num, arrLi) {
    for (var i = 0; i < arrLi.length; i++) {
        var obj = arrLi[i];
        var addclass = i < num ? "icon icon-star" : "icon icon-star-empty xing_star_empty";
        $(obj).children('i').attr("class", addclass);
    }
};
//应聘管理建议反馈根据传入的最大长度限制内容
InboxEngineJob.CheckContentLength = function (maxLen, obj) {
    var content = $(obj).val();
    var length = content.length;
    if (length >= maxLen) {
        content = content.substring(0, maxLen);
        $(obj).val(content);
        $("#FeedBack_contentNum").html(invite_ContentNum.replace('{0}', maxLen).replace('{1}', maxLen));
        InboxEngineJob.showErrorTemp("Content", inboxNew_FeedBackLimit);
    }
    else {
        $("#FeedBack_contentNum").html(invite_ContentNum.replace('{0}', length).replace('{1}', maxLen));
        $("#err_Content").hide();
    }
};
//初始化应聘管理建议反馈
InboxEngineJob.FeedBackInit = function () {
    $("#newFeedBack").live('click', function () {
        EHR.ShowDivBox("#divCtlFeedBack");
        $("#err_Evaluate").hide();
        $("#FeedBack_contentNum").html(invite_ContentNum.replace('{0}', 0).replace('{1}', 450));
        InboxEngineJob.CheckContentLength(450, "#FeedBack_Content");
    });
    $("#FeedBack_Cancel").live('click', function () {
        EHR.CloseDivBox("#divCtlFeedBack");
    });
    var arrLi = $("#FeedBack_Evaluate").children(".valstar");
    InboxEngineJob.setStarFun(arrLi);
    //限制意见反馈弹框中内容的字数限制
    $("[id='FeedBack_Content']").live('paste keyup mouseup blur', function () {
        InboxEngineJob.CheckContentLength(450, this);
    });
}

/**
显示引导也，不需要镂空显示
imgPath 图片地址
usemap 使用<map>标签
imgLeft 图片定位left+像素
imgTop  图片定位top+像素
*/
InboxEngineJob.ShowGuide = function (imgPath, usemap, imgLeft, imgTop) {
    $("#maskDivBackground").remove();
    $("#divNewAd").remove();
    var maskDivBackground = $("<div id='maskDivBackground' style='background-color:#000;position:absolute;z-index:499;opacity:0.5;filter:alpha(opacity=50);left:0;top:0;width:100%;height:100%'></div>");
    maskDivBackground.css("height", $(document).height());
    maskDivBackground.css("width", $(document).width());
    maskDivBackground.appendTo("body");
    var divNewAd = $("<div id='divNewAd' style='position:absolute;z-index:501;left:0;top:0'><img style='border:0;outline:none;' Border=0 hidefocus='true'  onfocus='this.blur();' usemap='#" + usemap + "' /></div>");
    var divLeft = ($(window).width() - imgLeft) / 2;
    var divTop = ($(window).height() - imgTop) / 2;
    divNewAd.css("left", divLeft < 0 ? 0 : divLeft);
    divNewAd.css("top", divTop < 0 ? 0 : divTop);
    divNewAd.appendTo("body");
    // src='" + ImagePath+ imgPath + "'
    $('#divNewAd').find('img').attr('src', ImagePath + imgPath);
}
InboxEngineJob.InitGuidePage = function () {
//    if (browser.msie && parseInt(browser.version) < 10) {
//        var imgPath = "commonnew/guidepage/inboxGuid1.png";
//        InboxEngineJob.ShowGuide(imgPath, '1-2map', '580', '500');
//    }
//    else {
//        var imgPath = "commonnew/guidepage/inboxGuidIndex.gif?r=" + Math.random();
//        InboxEngineJob.ShowGuide(imgPath, '1-1map', '950', '590');
//    }
}
InboxEngineJob.ChangeGuid = function (imgPath, usemap, imgLeft, imgTop) {
    InboxEngineJob.ShowGuide(imgPath, usemap, imgLeft, imgTop);
}
InboxEngineJob.CloseGuid = function () {
    $("#maskDivBackground").remove();
    $("#divNewAd").remove();
    InboxEngineJob.SetGuidPage();
}
InboxEngineJob.SetGuidPage = function (url) {
    var postData = { doType: 'SetGuidPage' };
    EHR.Common_AsyncHandle("POST", "xml", "../Ajax/InboxResume/GlobalInboxCommonAjax.ashx", postData, function () { if (url) { window.location.href = url; } }, 0);
    return true;
}
InboxEngineJob.GuidPageChange = function (url) {
    InboxEngineJob.SetGuidPage(url);
}


